var panelTracker = false;

Ext.onReady(function(){
   new Ext.Window({
        id: "rm_hospitality_list_person_picker",
        layout: "form",
        width: 270,
        bodyStyle : "padding:10px;",
        floating: true,
        border:false,
        resizable:false,
        closable:true,
        closeAction: 'hide',
        preventBodyReset: true
    });
});

function rm_hospitality_showPersonSelection(uid, unitname){

    if (!panelTracker){
        var htmlVar = document.getElementById('peopleselection_'+uid).innerHTML;
        var panel = Ext.getCmp("rm_hospitality_list_person_picker");
        panel.setAnimateTarget("RM_Hospitality_list_add_to_cart_"+uid);
        panel.html = htmlVar;
        panel.setTitle(unitname)
        panel.show();
        panelTracker = true;
    } else {
        Ext.getCmp("rm_hospitality_list_person_picker").hide();
        panelTracker = false;
    }
}

function rm_hospitality_unit_list_addtocart(uid){

    var otherInfoArray = {k: "board_type", value: boardtypeselect};

    var conn = new Ext.data.Connection();
    var request = {
        url: RM.Common.AssembleURL({
            controller : 'Reservations',
            action: 'addtocartJson'
        }),
        params: {
            unit_id : uid,
            adults: adultsSelection,
            children: childrenSelection,
            infants: infantsSelection,
            otherinfo: Ext.util.JSON.encode(otherInfoArray)
        },
        method: 'POST',
        success: function(responseObject) {
            var jsonObject = RM.Common.JSON.decode(responseObject.responseText, true);
            if (jsonObject.success) {
                RM.Common.Message.msg(
                    RM.Translate.User.Unit.List.Cart,
                    RM.Translate.User.Unit.List.AddedtoCart,
                    3,
                    "RM_popup_msg_div"
                );
                Ext.getCmp("rm_hospitality_list_person_picker").hide();
            } else {
                RM.Common.Message.msg(
                    RM.Translate.User.Unit.List.Cart,
                    jsonObject.error,
                    3,
                    "RM_popup_msg_div"
                );
            }
        },
        failure: function(){
            RM.Common.Message.msg(
                RM.Translate.User.Unit.List.Cart,
                RM.Translate.User.Unit.List.ServerUnavailable,
                3,
                "RM_popup_msg_div"
            );
        }
    };
    conn.request(request);
}

